package everydayone.rightSideView;

import java.util.LinkedList;
import java.util.List;

import twobranchTree.preorderTraversal.TreeNode;

/**
 * @Date 2020/04/20
 * @author 18795
 * @Thinking 使用层序遍历
 */
public class MyMethodOne {
	public List<Integer> rightSideView(TreeNode root) {
		List<Integer> ret = new LinkedList<Integer>();
		LinkedList<TreeNode> help = new LinkedList<TreeNode>();
		if( root==null ) return ret;
		help.add( root );
		while( !help.isEmpty() ) {
			int size = help.size();
			TreeNode next = null;
			for(int i=0 ; i<size ; i++) {
				next = help.poll();
				if( next.left!=null ) help.offer(next.left);
				if( next.right!=null ) help.offer(next.right);
			}
			ret.add(next.val);
		}
		return ret;
    }
}
